"use strict"
global.targetDirPath = process.env.PWD || process.cwd && process.cwd()
const minimist = require('minimist')
const packageJson = require('../package.json')
const { helpValue } = require('./constant')
const { buildHelpTemplate } = require('./util')
const createTask = require('./task/create')
const buildTask = require('./task/build')
const analyseTask = require('./task/analyse')


function taskSplit(argv) {
    // 打印帮助信息
    if (argv['h'] || argv['help']) {
        console.log(buildHelpTemplate(helpValue))
        return
    }

    // 打印版本号
    if (argv['v'] || argv['version']) {
        console.log('v' + packageJson.version || '0.0.1')
        return
    }

    // 下载模板
    if (argv['c'] || argv['create']) {
        createTask(argv)
        return
    }

    // 分析代码
    if (argv['a'] || argv['analyse']) {
        analyseTask(argv)
        return
    }

    // 编译
    buildTask(argv)
}


module.exports = () => {
    // 定义所需变量
    const argv = minimist(process.argv)

    // 根据启动命令分发任务
    taskSplit(argv)
}